<?php
session_start();

if (isset($_SERVER['HTTP_REFERER'])) {
    if ($_SERVER['HTTP_REFERER'] == 'http://localhost/RailwayWeb/logout.php' ||
            $_SERVER['HTTP_REFERER'] == 'http://localhost/RailwayWeb/login.php') {
        $_SESSION['previouspage'] = 'index.php';
    } else {
        $_SESSION['previouspage'] = $_SERVER['HTTP_REFERER'];
    }
} else {
    $_SESSION['previouspage'] = 'index.php';
}
//$_SESSION['previouspage'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'index.php' ;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />  
        <title>Railway Official Website</title>
        <link rel="stylesheet" href="css/foundation.css"/>
        <link rel="stylesheet" href="css/normalize.css"/>
        <link rel="stylesheet" href="css/jquery-ui.css" />
        <script src="js/vendor/jquery.js"></script>
        <script src="js/ui/jquery-ui.js"></script>
        <script src="js/vendor/custom.modernizr.js"></script>
        <script src="js/formValidation.js"></script>
    </head>
    <body>
        <div>
            <nav class="top-bar">
                <ul class="title-area">
                    <li class="name" onClick="void(0);">
                        <h1><a href="#">Railway Official Website</a></h1>
                    </li>
                    <li class="divider"></li>
                    <li class="toggle-topbar menu-icon">
                        <a href="#"><span>menu</span></a>
                    </li>
                </ul>
                <section class="top-bar-section">
                    <ul class="right">
                        <li class="divider"></li>
                        <li><a href="index.php">Home</a></li>
                        <li class="divider"></li>
                        <li><a href="#">Forum</a></li>
                        <li class="divider"></li>
                        <li><a href="loginPage.php">Login</a></li>
                        <li class="divider"></li>
                    </ul>
                </section>
            </nav>
        </div>
        <div class="row">
            <div class="large-6 columns large-offset-3">
                <h4>Login</h4>
                <form method="post" action="login.php" class="custom">
                    <fieldset>

                        <div class="row">
                            <div class="large-5 columns">
                                <select id="logintype" name="logintype">
                                    <option value="uid">UID</option>
                                    <option value="username">Username</option>
                                </select>
                            </div>
                            <div class="large-7 columns">
                                <input id="user" name="user" type="text" placeholder="Enter your username/uid" onblur="validateUsername();"/>
                                <small id="userError" class="error" style="display: none"></small>
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-5 columns">
                                <label for="password" class="left inline">Password</label>
                            </div>
                            <div class="large-7 columns">
                                <input id="password" name="password" type="password" placeholder="Enter your password" onblur="validatePassword();"/>
                                <small id="pswdError" class="error" style="display:none"></small>
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-12 columns">
                                <input type="submit" value="Login" class="right small button"/>
                                <input type="hidden" name="submitted" value="true"/>
                                <hr/>
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-12 left columns">
                                <small><a href="register.php">Not a member? Click here for register.</a></small><br/><br/>
                                <small><a href="forgetPassword.php">Forgot password?</a></small>
                            </div>
                        </div>
                    </fieldset>
                </form>
            </div>
        </div>
        <footer class="row">
            <div class="large-12 columns">
                <hr />
                <div class="row">
                    <div class="large-4 columns">
                        <p>&copy; Copyright 2013.</p>
                    </div>
                    <div class="large-6 columns">
                        <ul class="inline-list right">
                            <li><a href="aboutus.php">About Us</a></li>
                            <li><a href="contactus.php">Contact Us</a></li>
                            <li><a href="terms.php">Terms and Condition</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </footer>
        <script src="js/foundation.min.js"></script>
        <script>
                        $(document).foundation();
        </script>
    </body>
</html>
